package com.JD.DiselLog;


import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Yogesh
 */
public class AddDataToDataBase {

    public AddDataToDataBase(String totalQuantity) {

     SessionFactory  sessionFactory=com.JD.Disel.Hibernate.DiselLog_HibernateUtil.getSessionFactory();
        Session session=sessionFactory.openSession();
        Transaction transaction=session.beginTransaction();


            Query query=session.createQuery("from com.JD.Disel.Hibernate.Currentdisellog");

        List list=query.list();

        for (Object object : list) {

            com.JD.Disel.Hibernate.Currentdisellog currentdisellog=(com.JD.Disel.Hibernate.Currentdisellog)object;

            currentdisellog.setCurrentQuantity(totalQuantity);
            currentdisellog.setTotalQuantity(totalQuantity);

            session.save(currentdisellog);
            transaction.commit();

        }


    }

    AddDataToDataBase() {
       
    }


    String getCurrentQuentity(){

        String log="";

          SessionFactory  sessionFactory=com.JD.Disel.Hibernate.DiselLog_HibernateUtil.getSessionFactory();
        Session session=sessionFactory.openSession();
        Transaction transaction=session.beginTransaction();


            Query query=session.createQuery("from com.JD.Disel.Hibernate.Currentdisellog");

        List list=query.list();

        for (Object object : list) {

            com.JD.Disel.Hibernate.Currentdisellog currentdisellog=(com.JD.Disel.Hibernate.Currentdisellog)object;

            log=currentdisellog.getCurrentQuantity();

        }

        return log;
    }

    

   

}
